
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/29/2012 12:24:26
-- Generated from EDMX file: E:\Program Files\Documents\kantchiaki\Galnote\Galnote.Web\GalnoteModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [GalnoteData];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MakeFriends_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MakeFriends] DROP CONSTRAINT [FK_MakeFriends_User];
GO
IF OBJECT_ID(N'[dbo].[FK_MakeFriends_User1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MakeFriends] DROP CONSTRAINT [FK_MakeFriends_User1];
GO
IF OBJECT_ID(N'[dbo].[FK_MyUploadIMG]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProductSet] DROP CONSTRAINT [FK_MyUploadIMG];
GO
IF OBJECT_ID(N'[dbo].[FK_MyFavorites_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MyFavorites] DROP CONSTRAINT [FK_MyFavorites_User];
GO
IF OBJECT_ID(N'[dbo].[FK_MyFavorites_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MyFavorites] DROP CONSTRAINT [FK_MyFavorites_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_Discuss_Comment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Discuss] DROP CONSTRAINT [FK_Discuss_Comment];
GO
IF OBJECT_ID(N'[dbo].[FK_Discuss_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Discuss] DROP CONSTRAINT [FK_Discuss_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_TagProduct_Tag]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TagProduct] DROP CONSTRAINT [FK_TagProduct_Tag];
GO
IF OBJECT_ID(N'[dbo].[FK_TagProduct_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TagProduct] DROP CONSTRAINT [FK_TagProduct_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_SMS_Mail]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SMS] DROP CONSTRAINT [FK_SMS_Mail];
GO
IF OBJECT_ID(N'[dbo].[FK_SMS_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SMS] DROP CONSTRAINT [FK_SMS_User];
GO
IF OBJECT_ID(N'[dbo].[FK_ProductPopularity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ScoreSet] DROP CONSTRAINT [FK_ProductPopularity];
GO
IF OBJECT_ID(N'[dbo].[FK_Selection]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ScoreSet] DROP CONSTRAINT [FK_Selection];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[TagSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TagSet];
GO
IF OBJECT_ID(N'[dbo].[ProductSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductSet];
GO
IF OBJECT_ID(N'[dbo].[ScoreSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ScoreSet];
GO
IF OBJECT_ID(N'[dbo].[MailSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MailSet];
GO
IF OBJECT_ID(N'[dbo].[CommentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommentSet];
GO
IF OBJECT_ID(N'[dbo].[MakeFriends]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MakeFriends];
GO
IF OBJECT_ID(N'[dbo].[MyFavorites]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MyFavorites];
GO
IF OBJECT_ID(N'[dbo].[Discuss]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Discuss];
GO
IF OBJECT_ID(N'[dbo].[TagProduct]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TagProduct];
GO
IF OBJECT_ID(N'[dbo].[SMS]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SMS];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Gender] int  NULL,
    [BloodTpye] int  NULL,
    [Location] nvarchar(max)  NULL,
    [Birthday] datetime  NULL,
    [OnlineTime] bigint  NOT NULL,
    [OS] nvarchar(max)  NULL,
    [PaintingTools] nvarchar(max)  NULL,
    [Sketchpad] nvarchar(max)  NULL,
    [Music] nvarchar(max)  NULL,
    [PaintingEnviron] nvarchar(max)  NULL,
    [RegisterTime] datetime  NOT NULL,
    [Account] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Sign] nvarchar(max)  NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Roles] int  NOT NULL
);
GO

-- Creating table 'TagSet'
CREATE TABLE [dbo].[TagSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Value] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ProductSet'
CREATE TABLE [dbo].[ProductSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Path] nvarchar(max)  NOT NULL,
    [Posted] datetime  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Respond] nvarchar(max)  NOT NULL,
    [AuthorId] int  NOT NULL
);
GO

-- Creating table 'ScoreSet'
CREATE TABLE [dbo].[ScoreSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Value] int  NOT NULL,
    [Project] nvarchar(max)  NOT NULL,
    [ProductId] int  NOT NULL,
    [VoterId] int  NOT NULL
);
GO

-- Creating table 'MailSet'
CREATE TABLE [dbo].[MailSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Theme] nvarchar(max)  NOT NULL,
    [Text] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'CommentSet'
CREATE TABLE [dbo].[CommentSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Content] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'MakeFriends'
CREATE TABLE [dbo].[MakeFriends] (
    [Invitees_Id] int  NOT NULL,
    [Inviters_Id] int  NOT NULL
);
GO

-- Creating table 'MyFavorites'
CREATE TABLE [dbo].[MyFavorites] (
    [Owners_Id] int  NOT NULL,
    [Favorites_Id] int  NOT NULL
);
GO

-- Creating table 'Discuss'
CREATE TABLE [dbo].[Discuss] (
    [Messages_Id] int  NOT NULL,
    [Products_Id] int  NOT NULL
);
GO

-- Creating table 'TagProduct'
CREATE TABLE [dbo].[TagProduct] (
    [Tags_Id] int  NOT NULL,
    [Products_Id] int  NOT NULL
);
GO

-- Creating table 'SMS'
CREATE TABLE [dbo].[SMS] (
    [Senders_Id] int  NOT NULL,
    [Receives_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TagSet'
ALTER TABLE [dbo].[TagSet]
ADD CONSTRAINT [PK_TagSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProductSet'
ALTER TABLE [dbo].[ProductSet]
ADD CONSTRAINT [PK_ProductSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ScoreSet'
ALTER TABLE [dbo].[ScoreSet]
ADD CONSTRAINT [PK_ScoreSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MailSet'
ALTER TABLE [dbo].[MailSet]
ADD CONSTRAINT [PK_MailSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CommentSet'
ALTER TABLE [dbo].[CommentSet]
ADD CONSTRAINT [PK_CommentSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Invitees_Id], [Inviters_Id] in table 'MakeFriends'
ALTER TABLE [dbo].[MakeFriends]
ADD CONSTRAINT [PK_MakeFriends]
    PRIMARY KEY NONCLUSTERED ([Invitees_Id], [Inviters_Id] ASC);
GO

-- Creating primary key on [Owners_Id], [Favorites_Id] in table 'MyFavorites'
ALTER TABLE [dbo].[MyFavorites]
ADD CONSTRAINT [PK_MyFavorites]
    PRIMARY KEY NONCLUSTERED ([Owners_Id], [Favorites_Id] ASC);
GO

-- Creating primary key on [Messages_Id], [Products_Id] in table 'Discuss'
ALTER TABLE [dbo].[Discuss]
ADD CONSTRAINT [PK_Discuss]
    PRIMARY KEY NONCLUSTERED ([Messages_Id], [Products_Id] ASC);
GO

-- Creating primary key on [Tags_Id], [Products_Id] in table 'TagProduct'
ALTER TABLE [dbo].[TagProduct]
ADD CONSTRAINT [PK_TagProduct]
    PRIMARY KEY NONCLUSTERED ([Tags_Id], [Products_Id] ASC);
GO

-- Creating primary key on [Senders_Id], [Receives_Id] in table 'SMS'
ALTER TABLE [dbo].[SMS]
ADD CONSTRAINT [PK_SMS]
    PRIMARY KEY NONCLUSTERED ([Senders_Id], [Receives_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Invitees_Id] in table 'MakeFriends'
ALTER TABLE [dbo].[MakeFriends]
ADD CONSTRAINT [FK_MakeFriends_User]
    FOREIGN KEY ([Invitees_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Inviters_Id] in table 'MakeFriends'
ALTER TABLE [dbo].[MakeFriends]
ADD CONSTRAINT [FK_MakeFriends_User1]
    FOREIGN KEY ([Inviters_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MakeFriends_User1'
CREATE INDEX [IX_FK_MakeFriends_User1]
ON [dbo].[MakeFriends]
    ([Inviters_Id]);
GO

-- Creating foreign key on [AuthorId] in table 'ProductSet'
ALTER TABLE [dbo].[ProductSet]
ADD CONSTRAINT [FK_MyUploadIMG]
    FOREIGN KEY ([AuthorId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MyUploadIMG'
CREATE INDEX [IX_FK_MyUploadIMG]
ON [dbo].[ProductSet]
    ([AuthorId]);
GO

-- Creating foreign key on [Owners_Id] in table 'MyFavorites'
ALTER TABLE [dbo].[MyFavorites]
ADD CONSTRAINT [FK_MyFavorites_User]
    FOREIGN KEY ([Owners_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Favorites_Id] in table 'MyFavorites'
ALTER TABLE [dbo].[MyFavorites]
ADD CONSTRAINT [FK_MyFavorites_Product]
    FOREIGN KEY ([Favorites_Id])
    REFERENCES [dbo].[ProductSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MyFavorites_Product'
CREATE INDEX [IX_FK_MyFavorites_Product]
ON [dbo].[MyFavorites]
    ([Favorites_Id]);
GO

-- Creating foreign key on [Messages_Id] in table 'Discuss'
ALTER TABLE [dbo].[Discuss]
ADD CONSTRAINT [FK_Discuss_Comment]
    FOREIGN KEY ([Messages_Id])
    REFERENCES [dbo].[CommentSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Products_Id] in table 'Discuss'
ALTER TABLE [dbo].[Discuss]
ADD CONSTRAINT [FK_Discuss_Product]
    FOREIGN KEY ([Products_Id])
    REFERENCES [dbo].[ProductSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Discuss_Product'
CREATE INDEX [IX_FK_Discuss_Product]
ON [dbo].[Discuss]
    ([Products_Id]);
GO

-- Creating foreign key on [Tags_Id] in table 'TagProduct'
ALTER TABLE [dbo].[TagProduct]
ADD CONSTRAINT [FK_TagProduct_Tag]
    FOREIGN KEY ([Tags_Id])
    REFERENCES [dbo].[TagSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Products_Id] in table 'TagProduct'
ALTER TABLE [dbo].[TagProduct]
ADD CONSTRAINT [FK_TagProduct_Product]
    FOREIGN KEY ([Products_Id])
    REFERENCES [dbo].[ProductSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TagProduct_Product'
CREATE INDEX [IX_FK_TagProduct_Product]
ON [dbo].[TagProduct]
    ([Products_Id]);
GO

-- Creating foreign key on [Senders_Id] in table 'SMS'
ALTER TABLE [dbo].[SMS]
ADD CONSTRAINT [FK_SMS_Mail]
    FOREIGN KEY ([Senders_Id])
    REFERENCES [dbo].[MailSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Receives_Id] in table 'SMS'
ALTER TABLE [dbo].[SMS]
ADD CONSTRAINT [FK_SMS_User]
    FOREIGN KEY ([Receives_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SMS_User'
CREATE INDEX [IX_FK_SMS_User]
ON [dbo].[SMS]
    ([Receives_Id]);
GO

-- Creating foreign key on [ProductId] in table 'ScoreSet'
ALTER TABLE [dbo].[ScoreSet]
ADD CONSTRAINT [FK_ProductPopularity]
    FOREIGN KEY ([ProductId])
    REFERENCES [dbo].[ProductSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductPopularity'
CREATE INDEX [IX_FK_ProductPopularity]
ON [dbo].[ScoreSet]
    ([ProductId]);
GO

-- Creating foreign key on [VoterId] in table 'ScoreSet'
ALTER TABLE [dbo].[ScoreSet]
ADD CONSTRAINT [FK_Selection]
    FOREIGN KEY ([VoterId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Selection'
CREATE INDEX [IX_FK_Selection]
ON [dbo].[ScoreSet]
    ([VoterId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------